/**
 * 
 */
package sk.gtug.googleek.client;

import sk.gtug.googleek.client.presenter.HomePresenter;
import sk.gtug.googleek.client.presenter.UpcomingActivitiesPresenter;
import sk.gtug.googleek.client.presenter.HomePresenter.HomeDisplay;
import sk.gtug.googleek.client.presenter.UpcomingActivitiesPresenter.UpcomingActivitiesDisplay;
import sk.gtug.googleek.client.view.HomePage;
import sk.gtug.googleek.client.view.UpcomingActivitiesPanel;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.place.shared.PlaceHistoryMapper;
import com.google.inject.Provides;
import com.google.inject.Singleton;

/**
 * @author ladislav.gazo
 */
public class MainModule extends AbstractGinModule {

	@Override
	protected void configure() {
		bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
//		bind(PlaceController.class);
		
		bind(HomeDisplay.class).to(HomePage.class);
		bind(UpcomingActivitiesDisplay.class).to(UpcomingActivitiesPanel.class);
		bind(ActivityMapper.class).to(GoogleekActivityMapper.class).in(Singleton.class);
	}
	
	@Provides
	@Singleton
	PlaceController providePlaceController(EventBus bus) {
		return new PlaceController(bus);
	}
	
	@Provides
	HomePresenter provideHomePresenter(HomeDisplay display, UpcomingActivitiesPresenter activitiesPresenter) {
		return new HomePresenter(display, activitiesPresenter);
	}
	
	@Provides
	UpcomingActivitiesPresenter provideUpcomingActivitiesPresenter(UpcomingActivitiesDisplay display) {
		return new UpcomingActivitiesPresenter(display);
	}

	@Provides
	@Singleton
	PlaceHistoryHandler providePlaceHistoryHandler(PlaceHistoryMapper mapper, PlaceController placeController, EventBus eventBus) {
		PlaceHistoryHandler handler = new PlaceHistoryHandler(mapper);
		handler.register(placeController, eventBus, Place.NOWHERE);
		return handler;
	}
	
	@Provides
	@Singleton
	ActivityManager provideActivityManager(ActivityMapper mapper, EventBus eventBus) {
		return new ActivityManager(mapper, eventBus);
	}	
}
